src: add missing if/else braces
authorÁlvaro Fernández Rojas <[email protected]>
Tue, 4 Nov 2025 13:52:00 +0000 (14:52 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Tue, 4 Nov 2025 15:27:56 +0000 (16:27 +0100)
The linux kernel coding style suggests using braces in all if/else blocks
if at least one of the blocks has multiple statements:
https://docs.kernel.org/process/coding-style.html
Let's follow that coding style since it makes the code easier to follow.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv6.c
src/odhcp6c.c

index 0aa9daf32f6607ea53c838280b91467865425102..9c424ff0e9db8aab992f24d91bf30cff31a0f973 100644 (file)
@@ -1027,13 +1027,12 @@ static bool dhcpv6_response_is_valid(const void *buf, ssize_t len,
                if (rep->msg_type != DHCPV6_MSG_ADVERT &&
                                rep->msg_type != DHCPV6_MSG_REPLY)
                        return false;
-
        } else if (type == DHCPV6_MSG_UNKNOWN) {
                if (!accept_reconfig || rep->msg_type != DHCPV6_MSG_RECONF)
                        return false;
-
-       } else if (rep->msg_type != DHCPV6_MSG_REPLY)
+       } else if (rep->msg_type != DHCPV6_MSG_REPLY) {
                return false;
+       }
 
        uint8_t *end = ((uint8_t*)buf) + len, *odata = NULL,
                rcmsg = DHCPV6_MSG_UNKNOWN;
@@ -1113,9 +1112,10 @@ static bool dhcpv6_response_is_valid(const void *buf, ssize_t len,
                        if (olen < -4 + sizeof(struct dhcpv6_ia_hdr))
                                options_valid = false;
                } else if ((otype == DHCPV6_OPT_IA_ADDR) || (otype == DHCPV6_OPT_IA_PREFIX) ||
-                               (otype == DHCPV6_OPT_PD_EXCLUDE))
+                               (otype == DHCPV6_OPT_PD_EXCLUDE)) {
                        // Options are not allowed on global level
                        options_valid = false;
+               }
        }
 
        if (!options_valid || ((odata + olen) > end))
@@ -1395,8 +1395,7 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
                                if (!(client_options & DHCPV6_IGNORE_OPT_UNICAST))
                                        server_addr = *(struct in6_addr *)odata;
 
-                       }
-                       else if (otype == DHCPV6_OPT_STATUS && olen >= 2) {
+                       } else if (otype == DHCPV6_OPT_STATUS && olen >= 2) {
                                uint8_t *mdata = (olen > 2) ? &odata[2] : NULL;
                                uint16_t mlen = (olen > 2) ? olen - 2 : 0;
                                uint16_t code = ((int)odata[0]) << 8 | ((int)odata[1]);
@@ -1405,9 +1404,9 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
                        } else if (otype == DHCPV6_OPT_DNS_SERVERS) {
                                if (olen % 16 == 0)
                                        odhcp6c_add_state(STATE_DNS, odata, olen);
-                       } else if (otype == DHCPV6_OPT_DNS_DOMAIN)
+                       } else if (otype == DHCPV6_OPT_DNS_DOMAIN) {
                                odhcp6c_add_state(STATE_SEARCH, odata, olen);
-                       else if (otype == DHCPV6_OPT_SNTP_SERVERS) {
+                       else if (otype == DHCPV6_OPT_SNTP_SERVERS) {
                                if (olen % 16 == 0)
                                        odhcp6c_add_state(STATE_SNTP_IP, odata, olen);
                        } else if (otype == DHCPV6_OPT_NTP_SERVER) {
@@ -1427,9 +1426,9 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
                        } else if (otype == DHCPV6_OPT_SIP_SERVER_A) {
                                if (olen == 16)
                                        odhcp6c_add_state(STATE_SIP_IP, odata, olen);
-                       } else if (otype == DHCPV6_OPT_SIP_SERVER_D)
+                       } else if (otype == DHCPV6_OPT_SIP_SERVER_D) {
                                odhcp6c_add_state(STATE_SIP_FQDN, odata, olen);
-                       else if (otype == DHCPV6_OPT_INFO_REFRESH && olen >= 4) {
+                       else if (otype == DHCPV6_OPT_INFO_REFRESH && olen >= 4) {
                                refresh = ntohl_unaligned(odata);
                        } else if (otype == DHCPV6_OPT_AUTH) {
                                        struct dhcpv6_auth *r = (void*)&odata[-4];
@@ -1470,8 +1469,9 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
                                        odhcp6c_add_state(STATE_S46_MAPE, odata, olen);
                        } else if (otype == DHCPV6_OPT_S46_CONT_LW) {
                                odhcp6c_add_state(STATE_S46_LW, odata, olen);
-                       } else
+                       } else {
                                odhcp6c_add_state(STATE_CUSTOM_OPTS, &odata[-4], olen + 4);
+                       }
 
                        if (!dopt || !(dopt->flags & OPT_NO_PASSTHRU))
                                odhcp6c_add_state(STATE_PASSTHRU, &odata[-4], olen + 4);
@@ -2051,8 +2051,9 @@ int dhcpv6_send_request(enum dhcpv6_msg type)
                        delay = dhcpv6_rand_delay(retx->init_timeo * 1000);
 
                retx->rto = (retx->init_timeo * 1000 + delay);
-       } else
+       } else {
                retx->rto = (2 * retx->rto + dhcpv6_rand_delay(retx->rto));
+       }
 
        if (retx->max_timeo && (retx->rto >= retx->max_timeo * 1000)) {
                retx->rto = retx->max_timeo * 1000 +
index 85d9891ae1a1854e1ce88b87bac5ce30aabc945d..f73079847f59ab425f1582f3f077a743892b9e0b 100644 (file)
@@ -219,8 +219,9 @@ int main(_unused int argc, char* const argv[])
 
                                        help = true;
                                }
-                       } else
+                       } else {
                                help = true;
+                       }
 
                        free(o_data);
                        break;
@@ -243,8 +244,9 @@ int main(_unused int argc, char* const argv[])
                                        return 1;
                                }
                                optpos++;
-                       } else
+                       } else {
                                optpos = optarg;
+                       }
 
                        char *iaid_begin;
                        int iaid_len = 0;
@@ -283,8 +285,9 @@ int main(_unused int argc, char* const argv[])
                                        syslog(LOG_ERR, "Failed to override client-ID");
                                        return 1;
                                }
-                       } else
+                       } else {
                                help = true;
+                       }
                        break;
 
                case 'i':
@@ -330,8 +333,9 @@ int main(_unused int argc, char* const argv[])
 
                                        help = true;
                                }
-                       } else
+                       } else {
                                help = true;
+                       }
 
                        free(o_data);
                        break;
@@ -1000,8 +1004,9 @@ bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new,
                x->t1 = new->t1;
                x->t2 = new->t2;
                x->iaid = new->iaid;
-       } else if (odhcp6c_add_state(state, new, odhcp6c_entry_size(new)))
+       } else if (odhcp6c_add_state(state, new, odhcp6c_entry_size(new))) {
                return false;
+       }
 
        return true;
 }
@@ -1038,8 +1043,9 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed, bool
                if (!c->valid && remove_expired) {
                        odhcp6c_remove_state(state, ((uint8_t*)c) - start, odhcp6c_entry_size(c));
                        start = odhcp6c_get_state(state, &len);
-               } else
+               } else {
                        c = odhcp6c_next_entry(c);
+               }
        }
 }